package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArDonations;
import net.sk.china.city.service.IArDonationsService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 捐赠物品Controller
 * 
 * @author gxf
 * @date 2024-04-07
 */
@Api(tags = "捐赠物品")
@RequiredArgsConstructor
@RestController
@RequestMapping("/donate/donations")
public class ArDonationsController extends BaseController
{
    @Autowired
    private IArDonationsService arDonationsService;

    /**
     * 查询捐赠物品列表
     */
    @PreAuthorize("hasAnyAuthority('donate:donations:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArDonations arDonations)
    {
        startPage();
        List<ArDonations> list = arDonationsService.selectArDonationsList(arDonations);
        return getDataTable(list);
    }

    /**
     * 导出捐赠物品列表
     */
    @PreAuthorize("hasAnyAuthority('donate:donations:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArDonations arDonations)
    {
        List<ArDonations> list = arDonationsService.selectArDonationsList(arDonations);
//        ExcelUtil<ArDonations> util = new ExcelUtil<ArDonations>(ArDonations.class);
//        util.exportExcel(response, list, "捐赠物品数据");
    }

    /**
     * 获取捐赠物品详细信息
     */
    @PreAuthorize("hasAnyAuthority('donate:donations:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arDonationsService.selectArDonationsById(id));
    }

    /**
     * 新增捐赠物品
     */
    @PreAuthorize("hasAnyAuthority('donate:donations:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArDonations arDonations)
    {
        return toAjax(arDonationsService.insertArDonations(arDonations));
    }

    /**
     * 修改捐赠物品
     */
    @PreAuthorize("hasAnyAuthority('donate:donations:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArDonations arDonations)
    {
        return toAjax(arDonationsService.updateArDonations(arDonations));
    }

    /**
     * 删除捐赠物品
     */
    @ApiOperation("删除捐赠物品")
    @PreAuthorize("hasAnyAuthority('donate:donations:remove')")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(arDonationsService.deleteArDonationsById(id));
    }
}
